package com.leyou.item.servcie.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.entity.Category;
import com.leyou.item.mapper.CategoryBrandMapper;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.servcie.CategoryBrandService;
import com.leyou.item.servcie.CategoryService;
import com.leyou.pojo.dto.CategoryDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    private CategoryBrandService categoryBrandService;
    @Autowired
    private CategoryBrandMapper categoryBrandMapper;
    @Override
    public List<CategoryDto> queryCategoryByBrandId(Long id) {
        //根据品牌id查询种类id
        List<Long> longs = categoryBrandMapper.queryCategoryIdByBrandId(id);
        System.out.println("longs = " + longs);
        List<Long> categoryIds = categoryBrandService.queryCategoryIdByBrandId(id);
        //根据种类id查询详细信息
        List<Category> categoryList = listByIds(categoryIds);
        //转换成dto
        List<CategoryDto> categoryDtoList = categoryList.stream().map(CategoryDto::new).collect(Collectors.toList());
        return categoryDtoList;
    }
}
